import { result } from 'lodash';
/*
 * @Description: 
 * @Autor: 商晓彬
 * @Date: 2021-06-07 09:06:14
 * @LastEditors: 商晓彬
 * @LastEditTime: 2021-12-22 19:44:26
 */
import { Component, Injector, Input, ViewChild } from '@angular/core';
import { AppConsts } from '@shared/AppConsts';
import { AppComponentBase } from '@shared/common/app-component-base';
import { PQualitWorkStepDto, QualityPlatformServiceProxy } from '@shared/service-proxies/service-proxies';
import { ModalDirective } from 'ngx-bootstrap';
import * as _ from 'lodash';
import { finalize } from 'rxjs/operators';
import { MessageService } from '@abp/message/message.service';

@Component({
    selector: 'look-path',
    templateUrl: './look-path.component.html',
    styleUrls: ['./look-path.component.less']
})
export class LookPathComponent extends AppComponentBase {
    //引入子组件
    @ViewChild('createOrEditModal') modal: ModalDirective;
    @Input() detail: any;

    //详情表信息
    processesName: any;  //工序名
    processesExplain: any;  //工序介绍
    workStepHeader: any;
    workStepData: any;
    tagList = [];
    active = false;
    //右侧工步信息
    workstepInfo: any;
    constructor(
        injector: Injector,
        private _messageService: MessageService,
        private _qualityPlatformServiceProxy: QualityPlatformServiceProxy
    ) {
        super(injector);
    }
    getUser(item) {
        let msg = item ? item.split('，') : [];
        // let result = [];
        // for (const i of msg) {
        //     let data = i.split('_');
        //     result.push(data);
        // }
        let rs = [];
        for (const item of msg) {
            let msg = item.split('*');
            let data = { name: undefined, time: undefined, url: undefined };
            data.name = msg[0];
            data.time = msg[1];
            data.url = msg[2];
            rs.push(data);
        }
        return rs;
    }
    //处理图片
    getImage(item) {
        let imageList = item ? item.split(',') : []
        let result = []
        imageList.forEach((e, i) => {
            if (e.includes('.mp4')) {
            } else {
                let a = e.split('_');
                a[a.length - 1]=a[a.length - 1].replace('thumbnail', '');
                let rs = a.join('');
                result.push({
                    source: rs,
                    thumbnail: rs,
                    title: ''
                })
            }
        })
        return result
    }
    getVideo(item) {
        let imageList = item ? item.split(',') : []
        let result = []
        imageList.forEach((e, i) => {
            if (e.includes('.mp4')) {
                result.push({
                    source: e,
                    thumbnail: e,
                    title: ''
                })
            }
        })
        return result
    }
    //     getImage(item) {
    //         if (item.length != 0) {
    //             for (let i = 0; i < item.length; i++) {
    //                 if (item[i].photoNo != null) {
    //                     let photoNo = item[i].photoNo.split(',');
    //                     let result = [];
    //                     photoNo.forEach((e, i) => {
    //                         result.push({
    //                             source: e,
    //                             thumbnail: e,
    //                             title: ''
    //                         })
    //                     });
    //                     this.workstepInfo.workStepOut.multimediaRecord[i].photoNo = result;
    //                 }
    //                 if (item[i].firstOperator!=null) {
    //                     let firstOperator = item[i].firstOperator.split(',');
    //                     let result = [];
    //                     firstOperator.forEach((e, i) => {
    //                         result.push({
    //                             source: e,
    //                             thumbnail: e,
    //                             title: ''
    //                         })
    //                     });
    //                     this.workstepInfo.workStepOut.multimediaRecord[i].firstOperator = result;
    //                 }
    //                 if (item[i].secondOperator!=null) {
    //                     let secondOperator = item[i].secondOperator.split(',');
    //                     let result = [];
    //                     secondOperator.forEach((e, i) => {
    //                         result.push({
    //                             source: e,
    //                             thumbnail: e,
    //                             title: ''
    //                         })
    //                     });
    //                     this.workstepInfo.workStepOut.multimediaRecord[i].secondOperator = result;
    //                 }
    //                 if (item[i].thirdOperator!=null) {
    //                     let thirdOperator = item[i].thirdOperator.split(',');
    //                     let result = [];
    //                     thirdOperator.forEach((e, i) => {
    //                         result.push({
    //                             source: e,
    //                             thumbnail: e,
    //                             title: ''
    //                         })
    //                     });
    //                     this.workstepInfo.workStepOut.multimediaRecord[i].thirdOperator = result;
    //                 }
    //                 if (item[i].fourthOperator!=null) {
    //                     let fourthOperator = item[i].fourthOperator.split(',');
    //                     let result = [];
    //                     fourthOperator.forEach((e, i) => {
    //                         result.push({
    //                             source: e,
    //                             thumbnail: e,
    //                             title: ''
    //                         })
    //                     });
    //                     this.workstepInfo.workStepOut.multimediaRecord[i].fourthOperator = result;
    //                 }
    //                 if (item[i].fifthOperator!=null) {
    //                     let fifthOperator = item[i].fifthOperator.split(',');
    //                     let result = [];
    //                     fifthOperator.forEach((e, i) => {
    //                         result.push({
    //                             source: e,
    //                             thumbnail: e,
    //                             title: ''
    //                         })
    //                     });
    //                     this.workstepInfo.workStepOut.multimediaRecord[i].fifthOperator = result;
    //                 }
    //             }
    //         }
    //     // let imageList = item ? item.split(',') : []
    //     //     let result = []

    //     // imageList.forEach((e, i) => {
    //     //     // this.images=[{source:'https://scpic.chinaz.net/files/pic/pic9/202105/bpic23276.jpg', thumbnail: 'https://scpic.chinaz.net/files/pic/pic9/202105/bpic23276.jpg', title:'Sopranos 1'}];
    //     //     result.push({
    //     //         source: e,
    //     //         thumbnail: e,
    //     //         title: ''
    //     //     })
    //     // })
    //         // for (let i = 0; i < imageList.length; i++) {
    //         //     result.push({
    //         //                 source: imageList[i],
    //         //                 thumbnail: imageList[i],
    //         //                 title: ''
    //         //             })
    //         // }
    //     // return result

    // }
    //根据工步查看详情
    getWorkStep() {
        let that = this;
        abp.ui.setBusy(undefined, '', 1);
        if (that.detail && that.detail.rWorkStepEntityId) {
            that._qualityPlatformServiceProxy.getWorkStepOut(that.detail.rWorkStepEntityId)
                .pipe(finalize(() => { }))
                .subscribe(result => {
                    this.tagList = [];

                    result.tableNameDictionary.forEach(e => {
                        this.tagList.push(e)
                    });
                    that.workstepInfo = result;
                    this.active = true;
                    this.modal.show();
                    that.processesName = result.processesName ? result.processesName : ''
                    that.processesExplain = result.processesExplain ? result.processesExplain : ''
                    that.onTabChange({ index: 0 });
                    abp.ui.clearBusy();
                });
        } else {
            that._messageService.info('暂无数据！')
        }

    }
    //查看新增任务
    show(): void {
        this.getWorkStep();

    }
    //tab 切换工步动态表
    onTabChange(event) {
        this.workStepHeader = this.workstepInfo.tableNameDictionary[event.index];
        this.workStepData = this.workstepInfo.workStepOut[this.workstepInfo.tableNameDictionary[event.index].tableKey];
    }
    //打开弹窗
    onShown(): void {
    }
    //关闭事件
    close(): void {
        this.active = false;
        this.modal.hide();
    }

    ngOnInit() {
    }

}
